﻿using SAEA.MVC;
using KeydbCommand.Models;
using KeydbCommand.Attr;
using KeydbCommand.Services;

namespace KeydbCommand.Controllers
{
    /// <summary>
    /// 配置处理api
    /// </summary>
    public class ConfigController : Controller
    {
        /// <summary>
        /// 设置配置
        /// </summary>
        /// <param name="config"></param>
        /// <returns></returns>
        [HttpPost]
        [Auth(false, true)]
        public ActionResult Set(Config config)
        {
            return Json(new ConfigService().Set(config));
        }

        /// <summary>
        /// 导入配置
        /// </summary>
        /// <param name="configs"></param>
        /// <returns></returns>
        [Auth(false, true)]
        [HttpPost]
        public ActionResult SetConfigs(string configs)
        {
            return Json(new ConfigService().SetConfigs(configs));
        }
        /// <summary>
        /// 获取全部配置
        /// </summary>
        /// <returns></returns>
        [Auth(false, true)]
        public ActionResult GetList()
        {
            return Json(new ConfigService().GetList());
        }

        /// <summary>
        /// 获取配置
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        [Auth(true)]
        public ActionResult Get(string name)
        {
            return Json(new ConfigService().Get(name));
        }

        /// <summary>
        /// 删除配置
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        [Auth(false, true)]
        [HttpPost]
        public ActionResult Rem(string name)
        {
            return Json(new ConfigService().Rem(name));
        }

    }
}
